#include <bits/stdc++.h>
using namespace std;
const int maxn = 500;
struct Node {
    int x, y, z;
} Q[maxn];
int head = 0, tail = -1;
int dir[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};// right -> left -> down -> up

int n = 4;
char G[maxn][maxn] = {
        {'A', 'B', '/', 'D'},
        {'E', 'F', '/', 'H'},
        {'I', '/', 'H', 'L'},
        {'M', '/', 'O', 'P'}
};
int book[maxn][maxn];
void bfs(int x, int y) {
    head=0,tail=-1;//每次都初始化队列
    Q[++tail] = {x, y};
    book[x][y] = 1;
    while (head <= tail) {
        x = Q[head].x;
        y = Q[head].y;
        cout << G[x][y];
        ++head;
        for (int i = 0; i < 4; i++) {
            int nx = x + dir[i][0];
            int ny = y + dir[i][1];
            if (nx < 0 || nx >= n || ny < 0 || ny >= n || book[nx][ny] == 1 || G[nx][ny] == '/')continue;
            Q[++tail] = {nx, ny};
            book[nx][ny] = 1;
        }
    }
}
int main() {
    bfs(0, 0);

}
